<%@page import="java.util.List"%>
<%@page import="com.jfinal.plugin.activerecord.Page"%>
<%@page import="com.hongye.app.model.ContentModel"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html class="fixed">

	<head>

		<!-- Basic -->
		<meta charset="UTF-8">
		<meta name="keywords" content="HTML5 Admin Template" />
		<meta name="description" content="Porto Admin - Responsive HTML5 Template">
		<meta name="author" content="okler.net">
		<!-- Mobile Metas -->
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<!-- Web Fonts  -->
		<!-- Vendor CSS -->
		<link rel="stylesheet" href="../admin/css/bootstrap.css" />
		<link rel="stylesheet" href="../admin/css/font-awesome/css/font-awesome.css" />
        <link rel="stylesheet" href="../admin/css/select2.css" />
		<!-- Theme CSS -->
		<link rel="stylesheet" href="../admin/css/theme.css" />
		<!-- Skin CSS -->
		<link rel="stylesheet" href="../admin/css/default.css" />
		<!-- Theme Custom CSS -->
		<!-- Theme Custom ../admin/css -->
		<script src="../admin/js/modernizr.js"></script>
		<script type="text/javascript" src="http://cdn.bootcss.com/ckeditor/4.5.11/ckeditor.js"></script>
		
	</head>

	<body>
		<section role="main" class="content-body" style="margin-top: 50px;">
			<!-- start: page -->
			<section class="panel">
				<header class="panel-heading">
					<h2 class="panel-title">公告统计</h2>
				</header>
				<div class="panel-body">
					<div class="row">
						<div class="col-sm-6">
							<div class="mb-md">
								<button id="addToTable" class="btn btn-primary" onclick="add();">添加新公告<i class="fa fa-plus"></i></button>
							</div>
						</div>
					</div>
					<div id="add" style="display:none"><br>
						类&nbsp;&nbsp;&nbsp;型：<SELECT id="type" style="width:100" name="type" selectedIndex="$!{type}"> 
								<OPTION value="0">用户须知</OPTION> 
								<OPTION value="1">法律声明</OPTION> 
								<OPTION value="2">店铺说明</OPTION> 
							</SELECT> 
						<p>标&nbsp;&nbsp;&nbsp;题：<input id="title" type="text" name="title"  /></p>
						<div class="m">
							<p>摘要内容：<font color="#FF0000">（*摘要限100字...）</font></p>
							<textarea id="summary" cols="110" rows="3" name="summary" > </textarea>
							<p>内&nbsp;&nbsp;&nbsp;容：</p>
							<textarea id="content" rows="12" cols="50" name="content"></textarea>
							<script type="text/javascript">CKEDITOR.replace('content');</script>
						</div>
						<a class="btn btn-facebook mb-md ml-xs mr-xs" onclick="agreeadd();">确定提交 </a>
                   		<a class="btn btn-facebook mb-md ml-xs mr-xs" onclick="hid();">取消</a>
					</div>
					<table class="table table-bordered table-striped mb-none" id="datatable-default">
						<thead>
							<tr>
								<th class="hidden-phone center">序号</th>
								<th class="hidden-phone center">类型</th>
								<th class="hidden-phone center">标题</th>
								<th class="hidden-phone center">摘要</th>
								<th class="hidden-phone center">内容</th>
								<th class="hidden-phone center">状态</th>
								<th class="hidden-phone center">创建时间</th>
								<th class="hidden-phone center">更新时间</th>
								<th class="hidden-phone center">操作</th>
							</tr>
						</thead>
						<tbody>
							<%List<ContentModel> list = (List)request.getAttribute("contentlist");
										for(int i=1;i<=list.size();i++){
											ContentModel cm = list.get(i-1);
										%>
										<tr class="gradeA">
											<td class="center hidden-phone"><%=i %></td>
											<td class="center hidden-phone"><%int type=cm.getInt("type"); 
											if(type == 0){out.println("用户须知");
											}else if(type == 1){out.println("法律声明");
											}else if(type == 2){out.println("店铺说明");} %></td>
											<td class="center hidden-phone"><%=cm.get("title") %></td>
											<td class="center hidden-phone"><a href="#" data-summary="<%=cm.get("summary") %>" onclick="summaryshow(this);" class="on-default remove-row">查看摘要</a></td>
											<td class="center hidden-phone"><a href="#" data-content="<%=cm.get("content") %>" onclick="contentshow(this);" class="on-default remove-row">查看内容</a></td>
											<td class="center hidden-phone"><%int status=cm.getInt("status"); 
											if(status == 0){out.println("禁用");}else if(status == 1){out.println("启用");} %></td>
											<td class="center hidden-phone"><%=cm.get("c_time") %></td>
											<td class="center hidden-phone"><%=cm.get("u_time") %></td>
											<td class="center hidden-phone" >
												<a href="../content/contentdetail?id=<%=cm.get("id")%>" class="on-default edit-row">修改</a>&nbsp;
												<a href="#" data-id="<%=cm.get("id") %>" onclick="deletecontent(this);" class="on-default remove-row">删除</a>
											</td>
										</tr>
										<%} %>
						</tbody>
					</table>
				</div>
			</section>
		</section>
		<!-- Specific Page Vendor -->
		<!-- Vendor -->
		<script src="../admin/js/jquery.js"></script>
		<script src="../admin/js/layer.js"></script>
		<script src="../admin/js/jquery-browser-mobile/jquery.browser.mobile.js"></script>
		<script src="../admin/js/bootstrap/js/bootstrap.js"></script>
		<script src="../admin/js/nanoscroller/nanoscroller.js"></script>
		<script src="../admin/js/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
		<script src="../admin/js/magnific-popup/magnific-popup.js"></script>
		<script src="../admin/js/jquery-placeholder/jquery.placeholder.js"></script>
		
		<!-- Specific Page Vendor -->
	<!--	<script src="js/select2.js"></script>-->
		<script src="../admin/js/jquery-datatables/media/js/jquery.dataTables.js"></script>
		<script src="../admin/js/jquery-datatables-bs3/assets/js/datatables.js"></script>
		
		<!-- Theme Base, Components and Settings -->
		<script src="../admin/js/theme.js"></script>
		
		<!-- Theme Custom -->
		<script src="../admin/js/theme.custom.js"></script>
		
		<!-- Theme Initialization Files -->
		<script src="../admin/js/theme.init.js"></script>


		<!-- Examples -->
		<script src="../admin/js/tables/examples.datatables.default.js"></script>
		<script src="../admin/js/tables/examples.datatables.row.with.details.js"></script>
		<script src="../admin/js/tables/examples.datatables.tabletools.js"></script>
		<script type="text/javascript">
			//显示添加div
			function add(){
				$("#add").css('display','block'); 
			}
			//隐藏添加div
			function hid(){
				$("#add").css('display','none'); 
			}
			//添加
			function agreeadd(){				
				var type = $("#type").val();
				var title = $("#title").val();
				var summary = $("#summary").val();
				var content = CKEDITOR.instances.content.getData();
				$.post('../content/addContent',
	                    {type:type,title:title,summary:summary,content:content}
						,function(data){
							if(data=='suc'){
								location.href='../content/contentView';
							}else if(data=='fal'){
								layer.msg('添加失败...', {icon: 5});
							}
				});
			}
			//删除
			function deletecontent(obj){
				layer.confirm('确定删除吗？', {icon: 3, title:'提示'}, function(index){
					var id = obj.getAttribute("data-id");
					var url = '../content/deleteContent?id=' + id;
					$.get(url, function(data){
						if(data=='suc'){
							location.href='../content/contentView';
						}else if(data=='fal'){
							alert('删除失败!');
						}
					});
					  layer.close(index);
				});
			}
			//展示摘要
			function summaryshow(obj){
				var summary = obj.getAttribute("data-summary");
				layer.open({
					  type: 1,
					  skin: 'layui-layer-demo', //样式类名
					  closeBtn: 0, //不显示关闭按钮
					  anim: 2,
					  shadeClose: true, //开启遮罩关闭
					  content: summary
					});
			}
			//展示内容
			function contentshow(obj){
				var content = obj.getAttribute("data-content");
				layer.open({
					  type: 1,
					  skin: 'layui-layer-demo', //样式类名
					  closeBtn: 0, //不显示关闭按钮
					  anim: 2,
					  shadeClose: true, //开启遮罩关闭
					  content: content
					});
			}
		</script>
	</body>

</html>